
    use: 'ie.ondevice.objectkit.extension.Function';
    
    /*
     * Typically speaking, deferring the execution of a function
     * involves the use of setTimeout, or in the case of periodically
     * invoking a function, setInterval
     */
    
    var millisecondsToWait= 1000
    ,   functionToExecute= function () 
        {
            alert(millisecondsToWait + ' expired');
        }
    ,   timeoutId= setTimeout(functionToExecute, millisecondsToWait);
    
    /*
     * To cancel the timeout, you must have a reference to the timeout id
     */
    
    clearTimeout(timeoutId);
    
    /*
     * Managing timeouts is generally recognised as being tricky, so many
     * libraries provide a way to defer a function, some of them by building
     * in the deferral logic into Function.prototype
     */
    
    Function.prototype.defer= function (interval) 
    {
        return setTimeout(this, interval);
    };
    
    /*
     * This makes things easier and more concise
     */
    
    function seeYouInTheFuture () 
    {
        alert ('executed');  
    };
    
    var timeoutId= seeYouInTheFuture.defer(100); // will execute in 100 milliseconds
    // unless we cancel it
    clearTimeout(timeoutId);
    
    /*
     * But what if we want to parameterise the function? We could do this
     */
    
    Function.prototype.defer= function (interval) 
    {
        // take a record of the arguments
        var presetArgs= Array.prototype.slice.call(arguments, 1);
        return setTimeout.apply(null, [this].concat(presetArgs));
    };
    
     function seeYouInTheFutureII (value) 
    {
        alert ('say ' + value);  
    };   
    
    var timeoutId= seeYouInTheFutureII.defer(100, 'hello'); // will alert 'say hello' in 100 ms
    
    /*
     * The ObjectKit defer implementation faciliates preseting arguments
     * like above, but also binding the functions execution scope. 
     */
    
    // assume the ObjectKit defer method is implemented
    
    var object= 
    {
        method: function (a, b) 
        {
            this.result= a+b;
        }
    }
    
    // Defer object.methods execution for 2.5 seconds, bind its execution scope
    // to object, and paramaterise the method with two values
    var deferred= object.method.defer(2500, object, 1, 1); 
    
    /*
     * Unlike other implementations, the return value of a deferred function
     * is an object that can be used to further influence the execution of 
     * a deferred function.
     */
    
    // we can add a callback- its sole argument is a boolean that lets you know
    // if the deferred function executed without throwing an error 
    
    deferred.onExecute= function (sucess) 
    {
        if (success)
        {
            // if the function returned a value, we can retrieve it using the
            // result property
            var result= deferred.result; 
            handleResult(result); // do something with the return value
        }
        else 
        {
            // if the function threw an error, we can retrieve it via the fault
            // property
            var fault= deferred.fault;
            handelFault(fault); // handle
        }
    };
    
    // or if its the case that we want to execute early, we can check if the
    // function has executed, by checking the hasExecuted property
    
    var doExecute= false;
    if (false === deferred.hasExecuted) 
    {
        if (doExecute) 
        {
            deferred.execute(); // and go ahead and execute it.
            // callbacks will still be invoked, and the deferred result and
            // fault properties will still be applied to the defferred object
            // so no need to change your result interception logic
        }
        else 
        {
            // you could just dispose of the deferred function- once you do
            // it will no longer be invokable and the deferred object will be
            // made eligible for garbage collection
            deffered.dispose();    
        }
    }
    
    // finally, you can check how long it actually took between creating
    // the deferred object and it executing it, and you can compare that to
    // the interval you supplied to the defer method
    
    var elapsed= deferred.executedOn - deferred.createdOn
    ,   interval=deferred.interval // this is the value you provided as the first argument
    ,   difference= interval - elapsed 
    
    if (difference < 0) // a minus value indicates execution later than expected
    {
        
    }
    else // the deferred executed later than expected
    {
        
    }
        
        
        
        
    
    
    
    
